/*
 *  This sketch sends a message to a TCP server
 *
 */

#include <WiFi.h>
#include <WiFiMulti.h>

WiFiMulti WiFiMulti;
WiFiClient client;
void setup()
{
    Serial.begin(115200);
    Serial.readBytesUntil()
    delay(10);

    // We start by connecting to a WiFi network
    WiFiMulti.addAP("ChinaNet-PkYX", "w784765727");

    Serial.println();
    Serial.println();
    Serial.print("Waiting for WiFi... ");

    while(WiFiMulti.run() != WL_CONNECTED) {
        Serial.print(".");
        delay(500);
    }

    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());

    delay(500);
    const uint16_t port = 33333;
    const char * host = "192.168.1.14"; // ip or dns

    Serial.print("Connecting to ");
    Serial.println(host);

    // Use WiFiClient class to create TCP connections

    ;
    while(client.connect(host, port) == 0)
    {
      delay(3000);
      Serial.print(".");
    }
    randomSeed(65535);
}
char msg[32] = {0};
void loop()
{
  if(client.connected())
  {
    sprintf(msg, "%d;%d;%d\r\n", random(65535),random(65535),random(65535));
    client.print(msg);
    delay(1000);    
  }
  else
  {
    ESP.restart();
  }
    
}
